import random
import string
# 定义密码可能包含的字符集
characters = string.ascii_letters + string.digits + string.punctuation + '_'


# 生成随机密码的函数
def generate_password(length=8):
    return ''.join(random.choice(characters) for i in range(length))


# 评估密码安全强度的函数
def check_password_strength(password):
    has_letter = any(char.isalpha() for char in password)
    has_digit = any(char.isdigit() for char in password)
    has_special = any(char in string.punctuation or char == '_' for char in password)
    if has_letter and has_digit and has_special:
        return "密码安全强度良好"
    else:
        return "密码安全强度较低，建议包含字母、数字和特殊字符"


# 生成并打印密码
password = generate_password()
print(f"生成的密码是: {password}")
# 评估并打印密码的安全强度
print(f"密码的安全强度: {check_password_strength(password)}")